<?php
require_once('db.php');
require_once('utils.php');

session_check(true);

if (isset($_GET['quit'])) {
	$_SESSION['auth'] = '';
} else {
	if (isset($_POST['send'])) {
		$u = $_POST['user'];
		$p = $_POST['pass'];

		if (empty($u) || empty($p)) {
			$error = 'Eh, rellena los campos';
		} else {
			if (!checkUser($u, $p)) {
				$error = 'Va a ser que no puedes entrar as&iacute;';
			} else {
                $_SESSION['auth'] = $u;
				header("Location: ".$userURL.$_SESSION['auth']);
				return;
			}
		}
	}
}

?>
<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
  <title><?php  echo $siteName." / Portada"; ?></title>
  <link rel="stylesheet" type="text/css" href="css/estilo.css" />
  <link rel="stylesheet" type="text/css" href="css/planet.css" />
  <link rel="icon" href="img/favicon.ico" type="image/vnd.microsoft.icon">
  <meta http-equiv=content-type content="text/html; charset=UTF-8">
  <link rel="alternate" type="application/rss+xml" title="portada" href="<?php echo $mainURL."/rss2.php?index=1"; ?>" />
 </head>

  <body>
<?php show_header("Welcome to ".$siteName); ?>

  <h3>&Uacute;ltimos sweets</h3>
  <div id="comments">
<?php 
  show_index_comments();
?>
</div>


<?php
if (!empty($error)) {
	echo '<div class="error">'.$error.'</div>';
}
if(isset($_SESSION) && !empty($_SESSION['auth']))
{
?>
  <div id="followers">
  <h3>Profile</h3>
  <div id="profile">
  <?php
    show_profile($user, $user);
  ?>
  </div>
 <h3>Followers</h3>
   <div id="followers1">
<?php $n = show_followers(); ?>
  </div>
</div>


<? } else { ?>
<div id="login">
   <h3>Autent&iacute;cate</h3>
   <form action="<?php print "index.php";?>" method="post" class="user">
     <label for="user">Usuario:</label><br />
     <input type="text" name="user" value="" /><br />
     <label for="pass">Contrase&ntilde;a:</label><br />
     <input type="password" name="pass" value="" /><br />
     <input type="submit" name="send" value="Entrar" />
     <a href="register.php" title="Reg&iacute;strate">Reg&iacute;strate</a>
   </form>
</div>



<?php

}
 pie();

?>

 </body>
</html>

